package cn.anecansaitin.whimsy.common.listener;

import cn.anecansaitin.whimsy.Whimsy;
import cn.anecansaitin.whimsy.common.capabilities.ComboHandler;
import cn.anecansaitin.whimsy.common.capabilities.battle.IBattleMode;
import cn.anecansaitin.whimsy.common.capabilities.IComboHandler;
import cn.anecansaitin.whimsy.common.capabilities.IManaStorage;
import cn.anecansaitin.whimsy.common.register.ModBlockEntities;
import cn.anecansaitin.whimsy.common.register.ModDataAttachments;
import cn.anecansaitin.whimsy.common.register.ModItems;
import net.minecraft.world.entity.EntityType;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;

@Mod.EventBusSubscriber(modid = Whimsy.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class AttachCapabilityEvent {
    @SubscribeEvent
    public static void attach(RegisterCapabilitiesEvent event) {
        //物品
        {
            //岩石权杖
            {
                //连招系统
                event.registerItem(IComboHandler.COMBO, (item, v) -> {
                    if (!item.hasData(ModDataAttachments.ROCK_SCEPTER_COMBO_HANDLER)) {
                        ComboHandler data = item.getData(ModDataAttachments.ROCK_SCEPTER_COMBO_HANDLER);
                        data.combo().putExtraData("itemStack", item);
                        return data;
                    } else {
                        return item.getData(ModDataAttachments.ROCK_SCEPTER_COMBO_HANDLER);
                    }
                }, ModItems.ROCK_SCEPTRE.get());
                //魔力
                event.registerItem(IManaStorage.MANA_STORAGE, (item, v) -> item.getData(ModDataAttachments.ROCK_SCEPTER_MANA_STORAGE), ModItems.ROCK_SCEPTRE.get());
            }
        }
        //方块
        {
            //岩石祭坛
            event.registerBlockEntity(Capabilities.ItemHandler.BLOCK, ModBlockEntities.ROCK_ALTAR.get(), (entity, side) -> entity.itemHandler);
        }
        //玩家
        {
            //战斗模式
            event.registerEntity(IBattleMode.BATTLE_MODE, EntityType.PLAYER, (player, v) -> player.getData(ModDataAttachments.BATTLE_MODE));
        }
    }
}
